package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.mapper.DishMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: DishController
 * Package: com.sky.controller.admin
 * Description:
 *
 * @Author 小龙
 * @Create 2025/9/26 8:34
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/admin/dish")
@Api("菜品相关接口")
public class DishController {

    private DishService dishService;

    public DishController(DishService dishService1) {
        this.dishService = dishService1;
    }


    /**
     * 新增菜品信息
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增菜品信息")
    public Result addDish(@RequestBody DishDTO dishDTO) {
        log.info("添加菜品信息：{}",dishDTO);
        dishService.addDish(dishDTO);
        return Result.success();
    }

    /**
     * 分页展示菜品信息
     * @param queryDTO
     * @return
     */
    @GetMapping("page")
    @ApiOperation("分页展示菜品信息")
    public Result<PageResult> page (DishPageQueryDTO queryDTO) {
        log.info("菜品分页展示：",queryDTO);
        PageResult pageResult = dishService.pageQuery(queryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("菜品批量删除")
    public Result deleteDish(@RequestParam List<Long> ids) {

        log.info("批量删除菜品：{}",ids);
        dishService.deleteDish(ids);
        return Result.success();
    }

    /**
     * 回显菜品菜单
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据菜品id获取菜品")
    public Result<DishVO> getDishById(@PathVariable Long id) {
        log.info("修改菜品id: {}",id);
        DishVO dishVO = dishService.getDishById(id);
        return Result.success(dishVO);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDish(@RequestBody DishDTO dishDTO) {
        log.info("修改菜品信息：{}",dishDTO);
        dishService.updateDish(dishDTO);

        return Result.success();
    }





}
